<!DOCTYPE html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
    <head>
    <meta charset="UTF-8">
    <title>添加报价表</title>
	<script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
	<script>
        var  selectIndex = -1;
		var path=$("#path").val();  
        function hideTable(){
            $("#searchdiv").toggle();
        }
        $(function(){
        		Date.prototype.format = function(format)
				{
				 var o = {
				 "M+" : this.getMonth()+1, //month
				 "d+" : this.getDate(),    //day
				 "h+" : this.getHours(),   //hour
				 "m+" : this.getMinutes(), //minute
				 "s+" : this.getSeconds(), //second
				 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
				 "S" : this.getMilliseconds() //millisecond
				 }
				 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
				 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
				 for(var k in o)if(new RegExp("("+ k +")").test(format))
				 format = format.replace(RegExp.$1,
				 RegExp.$1.length==1 ? o[k] :
				 ("00"+ o[k]).substr((""+ o[k]).length));
				 return format;
				}
        
                var customName=self.parent.$("#customName").val();
                $("#productList").datagrid({
                url:'/kxmanage/sellorderbill/findallofferpricebill',
                queryParams:{customName:customName},
                pageNumber:1,
                pageSize:5,
                pageList:[5,10],
                pagination:true,
                checkOnSelect:true,
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'code',title:'报价编号',width:140},
                    {field:'offerTime',title:'报价日期',width:200,
                         formatter:function(value,row,index){
                            return (new Date(value)).format("yyyy-MM-dd hh:mm:ss");
                         }
                    },
                    {field:'customName',title:'客户名称',width:100},
                    {field:'amount',title:'数量',width:70},
                    {field:'money',title:'总货值',width:80},
                    {field:'checkStatus',title:'审核状态',width:100,
                         formatter:function(value,row,index){
                         	if(row.checkStatus==1){
	                    		return "未审核";
	                    	}
                            return "已审核";
                        }
                    }
                ]],
                toolbar:'#wu_toolbar',
                onClickRow:function(index,data){
                  $(this).datagrid('unselectRow',index);
                }
            });
            
         $("#search_btn").click(function(){
	       var form=$("#form1");
  		 $("#productList").datagrid('load',serializeForm(form));
         });
         
          $("#reset_btn").click(function(){
	      $("#form1").form('reset');
  		    $("#productList").datagrid('load',{});
          });
         
         /* $.ajax({
         	type:"GET",//请求类型
		 	url:"/kxmanage/sellorderbill/findallpartname",//请求的url
		 	dataType:"json",//ajax接口（请求url）返回的数据类型
		 	success:function(data){//data：返回数据（json对象）
		 		if(data != null){
		 			$("#partTypeId").html("");
				var options = "<option value=\"0\">——请选择——</option>";
				for(var i = 0; i < data.length; i++){
					//alert(data[i].id);
					//alert(data[i].roleName);
					options += "<option value=\""+data[i].id+"\">"+data[i].typeName+"</option>";
				}
				$("#partTypeId").html(options);
				}
		 	}
         }) */
       $('#partTypeId').combobox({    
          url:'/kxmanage/sellorderbill/findallpartname',    
          valueField:'id',    
          textField:'typeName'   
       }); 
        
       })
        
        
        function addOfferPriceBill(){
          var row = $('#productList').datagrid('getSelections');
          var data=JSON.stringify(row);
          if(row!=null&&row!=''){
            $.ajax({
		        type:"get",//请求类型
		        url:"/kxmanage/sellorderbill/findpartbycode", 
		        data:{"data":data},
		        dataType:"json",//ajax接口（请求url）返回的数据类型
		        success:function(data){//data：返回数据（json对象）
                  parent.addOfferPriceBill(data); 
		        } 
             })
          }else{
            alert("请您选择报价表！")
          }
        }
        function closeOfferPriceBill(){
          parent.closeOfferPriceBill();
        }
        
        //将表单序列化
		function serializeForm(form){
			var obj={};
			$.each(form.serializeArray(),function(index){
				  if(obj[this['name']]){
					obj[this['name']]=obj[this['name']]+','+this['value']
				 }else{
				   obj[this['name']]=this['value'];
				 }
			});
			return obj;
		}  
     </script>
  </head>
  
  <body>
    <div id="wu_toolbar">
    <input type="hidden" id="path" value="${pageContext.request.contextPath}"/>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1"> 
            <table width="100%" border="0" cellspacing="0" style="background-color:#c9dfff;" >
                <tbody><tr>
                    <td width="100"><b>检索条件:</b></td>
                    <td width="70" align="right">报价编号:</td>
                    <td width="90" align="left"><input name="findcode" class="easyui-textbox" type="text" id="findcode" value="" maxlength="70" style="width:120px;height:30px" ></td>
                    <td width="70" align="right">开始日期:</td>
                    <td width="90" align="left"><input name="findstartDate" class="easyui-datetimebox" type="text" id="findstartDate" value="" maxlength="70" style="width:120px;height:30px"></td>
                    <td width="100" align="right">结束日期:</td>
                    <td width="90" align="left"><input name="findendDate" class="easyui-datetimebox" type="text" id="findendDate" value="" maxlength="70" style="width:120px;height:30px"></td>
                    <td width="72">
                        <a id="search_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="margin-left:10px">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>
                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">
</div>
<br/>
<div id="addButton" style="float:right">
  <a href="javascript:addOfferPriceBill()" class="easyui-linkbutton" style="margin-right: 10px">添加配件</a>
  <a href="javascript:closeOfferPriceBill()" class="easyui-linkbutton">退出</a>
</div>
</body>
</html>
